package com.flow;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, FlowBean, Text, Text> {

    @Override
    protected void reduce(Text phone,Iterable<FlowBean> fbs,Context context) throws IOException, InterruptedException {
        long upFlow = 0;
        long downFlow = 0;
        for (FlowBean fb : fbs){
            upFlow += fb.getUpFlow();
            downFlow +=  fb.getDownFlow();
        }
        FlowBean final_fb = new FlowBean(upFlow,downFlow);
        context.write(phone, new Text(final_fb.toString()));
    }
}

